package futbolfacil.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import futbolfacil.modelo.Cancha;
import futbolfacil.modelo.Local;
import futbolfacil.negocio.SeguridadNegocio;

/**
 * Servlet implementation class lstCanchasPorLocal
 */
@WebServlet("/lstCanchasPorLocal")
public class lstCanchasPorLocal extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public lstCanchasPorLocal() {
        super();
        // TODO Auto-generated constructor stub
       
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		SeguridadNegocio neg = new SeguridadNegocio();
		Collection<Cancha> lstCanchas = new ArrayList<Cancha>();
		int idLocal = Integer.parseInt(request.getParameter("idLocal"));
		
		try {
			lstCanchas = neg.listarCanchasPorLocal(idLocal);			
		} catch (Exception e) {
			//throw e.getMessage();
		}
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		out.println("<select id='cboCancha' name='cboCancha'>");
		out.println("<option value='0'>Seleccione cancha</option>");
		if(lstCanchas != null){
            for(Cancha x : lstCanchas){
                out.println("<option value='"+ x.getCodigoCancha() +"'>"+ x.getDescripcionCancha() +"</option>");
            }            
        }
		out.println("</select>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
